///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Ini file parser and write an ini file by it
///</describe>
/// <date>2021/1/31</date>
///***********************************************************************
#ifndef INI_H
#define INI_H

#include <atomic>
#include <iostream>
#include <string>

namespace SystemTool
{
	namespace IO
	{
		class Ini
		{
		public:
			// Construct the ini 
			Ini();

			// Destory the ini
			~Ini();

			// Copy the ini
			Ini(const Ini& other);

			// Assign the ini
			Ini& operator=(const Ini& other);

		public:
			// Configure the ini file path
			void Configure(std::string strFilePath);

			// Get key 
			bool GetKey(std::string strSessionName, std::string strKey, std::string& strValue);

			// Get key 
			bool GetKey(std::string strSessionName, std::string strKey, int& iValue);

			// Get key 
			bool GetKey(std::string strSessionName, std::string strKey, double& dValue);

			// Get key 
			bool GetKey(std::string strSessionName, std::string strKey, bool& bValue);

			// Set key 
			bool SetKey(std::string strSessionName, std::string strKey, std::string strValue);

			// Set key 
			bool SetKey(std::string strSessionName, std::string strKey, int iValue);

			// Set key 
			bool SetKey(std::string strSessionName, std::string strKey, double dValue);

			// Set key 
			bool SetKey(std::string strSessionName, std::string strKey, bool bValue);

		private:
			// Get key value
			template<class T>
			bool GetKeyValue(std::string strSessionName, std::string strKey, T& value);

			// Set key value
			template<class T>
			bool SetKeyValue(std::string strSessionName, std::string strKey, T& value);

		private:
			// Get the file path
			inline std::string GetFilePath() const
			{
				return m_strFilePath;
			}

			// Set the file path
			inline void SetFilePath(std::string strPath)
			{
				m_strFilePath = strPath;
			}

			// Get the Disposed
			inline bool GetDisposed() const
			{
				return m_bDisposed;
			}

			// Set the Disposed
			inline void SetDisposed(bool bDisposed)
			{
				m_bDisposed = bDisposed;
			}

		private:
			// Ini file path
			std::string m_strFilePath;

			// Dispose the ini
			std::atomic<bool> m_bDisposed;
		};
	}
}

#endif // INI_H
